package com.lp.multi.juc.collection;

import java.util.concurrent.CountDownLatch;

/**
 * @author: lp
 * @create: 2021-06-27 16:47
 * @description: 关门实例(减法计数器)
 */
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);
        System.out.println("放学了，教室还有10个同学");
        for (int i = 0; i < 10; i++) {
            final int number = i+1;
            new Thread(()->{
                System.out.println("第"+number+"个同学出教室了");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println("教室没人了，关门");
    }
}
